﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using UofCASE.AgileProductLinerDSL.Nant.Tasks.Models;
using System.IO;

namespace APLDTests.NantTests
{
    [TestClass]
    public class FeatureSetTest
    {
        [TestCleanup]
        public void teardown()
        {
            String dir = "../../../APLDTests/SampleProductLinerDir/Platforms/Windows/Results";
            if(Directory.Exists(dir)) Directory.Delete(dir, true);
        }

        [TestMethod]
        public void RunsAllTestsUnderASpecificPlatform()
        {
            String productlinerdir = "../../../APLDTests/SampleProductLinerDir";
            ProductLinerSet productLine = new ProductLinerSet("../../..", productlinerdir, "APLDTests.dll", "../../../APLDTests/AspenCollectionPlan.xml");
            IList<String> configs = new List<String>();
            configs.Add("../../../APLDTests/SampleProductLinerDir/Platforms/Windows/SampleModel.confeaturator");
            Platform windows = new Platform("Windows");
            productLine.AddPlatform(windows, configs);
            productLine.RunTestsFor(windows);
            Assert.IsTrue(productLine.GetPassed(windows));
            Feature profit = new Feature("Root Feature\\Alternative [1..1]\\Feature1");
            Assert.AreEqual(1, productLine.GetPassed(profit));
        }

        [TestMethod]
        public void ConstructsXmlResult()
        {
            String productlinerdir = "../../../APLDTests/SampleProductLinerDir";
            ProductLinerSet productLine = new ProductLinerSet("../../..", productlinerdir, "APLDTests.dll", "../../../APLDTests/AspenCollectionPlan.xml");
            IList<String> configs = new List<String>();
            configs.Add("../../../APLDTests/SampleProductLinerDir/Platforms/Windows/SampleModel.confeaturator");
            Platform windows = new Platform("Windows");
            productLine.AddPlatform(windows, configs);
            productLine.RunTestsFor(windows);

            String xml = windows.ToXml();
            Assert.AreEqual(
                "<Platform name=\"Windows\">\n" +
                "<Feature name=\"Root Feature\\Alternative [1..1]\\Feature1\">\n" +
                "<Test name=\"Feature1Test.html\" passed=\"True\" />\n" +
                "</Feature>\n" +
                "</Platform>\n",
                xml
            );
        }
    }
}
